﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace MedReg.Classes
{
    [Serializable]
    public class Award : ISerializable
    {
        private string numberField;

        private string nameField;

        private System.Nullable<System.DateTime> issuedField;
        private Employee employee;

        private static readonly Award theOneObject = new Award();

        public static Award GetAward()
        {
            return theOneObject;
        }

        /// <remarks/>
        public string Number
        {
            get
            {
                return this.numberField;
            }
            set
            {
                this.numberField = value;
            }
        }

        /// <remarks/>
        public string Name
        {
            get
            {
                return this.nameField;
            }
            set
            {
                this.nameField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
        public System.Nullable<System.DateTime> Issued
        {
            get
            {
                return this.issuedField;
            }
            set
            {
                this.issuedField = value;
            }
        }

        public Employee Employee
        {
            get
            {
                return this.employee;
            }
            set 
            {
                this.employee = value;
            }

        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //throw new NotImplementedException();
            info.AddValue("Number", numberField);
            info.AddValue("Name", nameField);
            info.AddValue("Issued", issuedField);
        }
        public Award()
        {
        }

        public List<Classes.Award> getAwardList(Classes.ArrayOfEmployee sEmployee)
        {

            foreach (var emp in sEmployee)
            {
                foreach (var award in emp.EmployeeAwards)
                {
                    award.Employee = emp;
                }
            }
            
            //var awd = sEmployee
            //    .SelectMany(award => award.EmployeeAwards, (Employees, Awards) => new { Employees, Awards })
            //    .Select(AwardsEx => new { Employee = AwardsEx.Employees, AwardsEx.Awards }).ToList();

            var awd = sEmployee.SelectMany(em => em.EmployeeAwards).ToList();
            
            return awd;
        }
    }

}
